/**
 * @Author 天下无敌
 * @Date 
 * @AIDE AIDE+ 
 */
package com.ecs.core.gsystem.player;
import com.ecs.core.gsystem.StageSystem;
import com.ecs.core.screen.ui.CustomJoystick;
import com.artemis.ComponentMapper;
import com.artemis.BaseEntitySystem;
import com.artemis.annotations.All;
import com.ecs.core.components.player.NearTagCom;
import com.ecs.core.components.attribute.MovementComp;

@All({NearTagCom.class})
public class PlayerRockerStystem extends BaseEntitySystem
{
	private StageSystem stage;
	private PlayerDataSystem player;
	private CustomJoystick joystick;
	private ComponentMapper<MovementComp> moves;
	
	@Override
	protected void initialize() {
		super.initialize();

		float joystickSize = stage.getStage().getHeight() * 0.4f; // 高度20%作为直径
		float knobRadius = joystickSize * 0.2f; // 手柄半径为摇杆区域的20%
		float deadzoneRadius = 10f; // 死区半径（像素）

		joystick = new CustomJoystick(deadzoneRadius, knobRadius);

		// 3. 设置摇杆区域大小（背景圆直径）
		joystick.setSize(joystickSize, joystickSize);

		float margin = 5f; // 边距
		joystick.setPosition(margin, margin);

		// 5. 添加到Stage
		stage.getStage().addActor(joystick);
	}
	
	@Override
	protected void processSystem()
	{
		MovementComp m = moves.get(player.getId());
		if(joystick.isTouched()){
			float mx = joystick.getKnobPercentX();
			float my = joystick.getKnobPercentY();
			
			m.velocity.set(mx,my).scl(m.moveSpeed);
		}else{
			m.velocity.setZero();
		}
	}
	
}
